package org.yoome.jtools.utils;


import com.google.common.util.concurrent.ThreadFactoryBuilder;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class ExecutorServiceUtil {
    private static int corePoolSize = 5;
    private static int maxPoolSize = 10;
    private static long aliveTime = 0L;
    private static int dequeueSize = 100;



    /**
     *  int maximumPoolSize,
     *                               long keepAliveTime,
     *                               TimeUnit unit,
     *                               BlockingQueue<Runnable> workQueue,
     *                               ThreadFactory threadFactory
     * @return
     */
    public static ExecutorService newExecutorService() {
        ExecutorService service = new ThreadPoolExecutor(corePoolSize,
                maxPoolSize,
                aliveTime,
                TimeUnit.SECONDS,
                new LinkedBlockingDeque<Runnable>(dequeueSize),
                new ThreadFactoryBuilder().setNameFormat("boot-pool-%d").build(),
                new ThreadPoolExecutor.AbortPolicy());

        return service;
    }
}
